package bookExercise;

import java.util.Scanner;

public class A6ThrowExceptionDemo {
    public static void main(String[] args) {
        A6AntiaddictInterface a6 =(age)->{
            if(age<18){
                throw new IllegalArgumentException("年龄不满18岁，禁止上网");
            }else{
                return true;
            }
        };
        Scanner sc =new Scanner(System.in);
        System.out.println("请输入年龄：");
        int age =sc.nextInt();
        try{
            if(a6.check(age)){
                System.out.println("年龄符合要求，允许上网");
            }
        }catch(IllegalArgumentException e){
            System.out.println(e.getMessage());
        }
        sc.close();
    }
}
